from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import Config
from flask_cors import CORS
from flask_avatars import Avatars
from flask_login import LoginManager


login_manager = LoginManager()      # 用户认证
db = SQLAlchemy()                   # 数据库
avatars = Avatars()                 # 用户头像


def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)
    # 配置用户认证信息
    login_manager.init_app(app)
    login_manager.session_protection = 'strong'  # 认证加密程度
    login_manager.login_view = 'main.login'  # 登陆认证的处理视图
    login_manager.login_message = u'对不起，您还没有登录'  # 登陆提示信息
    login_manager.login_message_category = 'info'
    db.init_app(app)
    avatars.init_app(app)
    CORS(app, supports_credentials=True)
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)
    app.app_context().push()
    return app
